from django.urls import path, re_path, include
from .views import RegisterView, LoginView, UsernameCountView, MobileCountView
from rest_framework.routers import SimpleRouter, DefaultRouter
from users import views
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
from users import views

router = DefaultRouter()
router.register(r'user', views.UserViewSet)
router.register(r'area', views.AreaViewSet)  # 1, 查找单个数据, 2, 查找批量数据, 3, 增加, 4, 修改, 5, 删除
router.register(r'address', views.AddressViewSet)  # 1, 查找单个数据, 2, 查找批量数据, 3, 增加, 4, 修改, 5, 删除

urlpatterns = [
    path('emails/', views.EmailAddView.as_view()),
    path('emails/verification/', views.EmailVerificationView.as_view()),
    path("register/", RegisterView.as_view()),
    # path('login/', LoginView.as_view()),
    re_path('usernames/(?P<username>[a-zA-Z0-9_-]{5,20})/count/', UsernameCountView.as_view()),
    re_path('mobiles/(?P<mobile>1[3-9]\d{9})/count/', MobileCountView.as_view()),
    path('login/', obtain_jwt_token),  # 获取token, 接收认证凭据(用户名,密码), 返回token
    path('refresh/', refresh_jwt_token),  # 刷新token, 接收旧token, 返回新token
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),  # 认证地址
]

urlpatterns += router.urls  # 路由模块
# print(router.urls)
